<?php
require_once("dao/DAOFactory.php");
require_once("dao/SecurityDAO.php");
require_once("dao/PlayerDAO.php");
require_once("model/Player.php");


class SessionMgmt{
	
	public function login($emailAddr,$pw){
		$me = null;
		$securityDao = DAOFactory::getDAO("security");
		$player = $securityDao->login($emailAddr,$pw);
		if($player != null && $player->playerid && is_numeric($player->playerid) && $player->playerid > 0){
			$playerDao = DAOFactory::getDAO("player");
			$me = $playerDao->getItem($player->playerid);
			$me = ($me->playerid != null)?$me:null;
		}
		return $me;	
	}
	
	public function updatePassword($playerid,$newPassword,$verified){
		try{
			if($stmt = $this->conn->prepare("CALL PLAYER_UPDATE_PASSWORD(?,?,?)")){
				$stmt->bind_param("isi",$playerid,$newPassword,$verified);
				$stmt->execute();	
			}
			else{
				printf("Error occurred in %s.<br/>Details: %s",__CLASS__,$stmt->error);
			}	
		}
		catch(Exception $e){
			printf("Error occurred in %s.<br/>Details: %s",__CLASS__,$e->getMessage());
		}
		$this->conn->close();
	}
}

?>
